package LeetCode.month01.day27;

public class No1888 {
    public static void main(String[] args) {
        System.out.println(minFlips("1110"));
    }
    public static int minFlips(String s) {
        int n = s.length();
        char[] chars = s.toCharArray();
        int res = n;
        int cnt = 0;
        for (int i = 0; i < n; i++) {
            if(chars[i]-'0'==i%2) cnt++;
        }
        res = Math.min(cnt,n-cnt);
        for (int i = n; i < 2*n-1; i++) {
            if(chars[i%n]-'0'==i%2) cnt++;
            if(chars[i-n]-'0'==(i-n)%2) cnt--;
            res = Math.min(res,Math.min(cnt,n-cnt));
        }
        return res;
    }
}
